package org.shoukaiseki.supersaiyan.common.config;

import org.shoukaiseki.common.utils.JacksonUtils;
import org.shoukaiseki.supersaiyan.common.utils.poi.ExcelUtil;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;


/**
 * 读取项目相关配置
 * 在 Application启动类中添加
     @Resource
     private SuperSaiyanConfig superSaiyanConfig;
     用于优先设置配置值
  *
  * @author sks
 */
@Component
@ConfigurationProperties(prefix = "supersaiyan")
public class SuperSaiyanConfig
{

    //webSocket 开发模式下的 webSocketUrl连接地址
    //正常模式下使用 系统配置里的信息
    //未使用
//    private String webSocketUrl="ws://localhost:10790/webSocket/";

    /**
     * jackson 反序列时的 timeZone
     * default  默认
     * none     不处理
     * GMT+8    +8区
     */
    private String jacksonDeserializationTimeZone="GMT+8";

    private String genCodeZipName ="SuperSaiyan";

    /** 用于设置 ExcelUtils.fontName 的字体名称 */
    private String fontName;

    /** 项目名称 */
    private String name;

    /** 版本 */
    private String version;

    /** 版权年份 */
    private String copyrightYear;

    /** 实例演示开关 */
    private boolean demoEnabled;

    /** 上传路径 */
    private static String profile;

    //excel转Html时的字符集, win下使用 "GKB"
    private static String excelToHtmlCharsetName;

    /** 获取地址开关 */
    private static boolean addressEnabled;

    /** 验证码类型 */
    private static String captchaType;

    //能否清除数据
    private static boolean clearDataEnabled=false;

    //redis 所有key前缀,暂时未全部修改
    private static String redisRootKeyPrefix="superSaiyan:";

    //上传文件时的配置
    private static String multipartConfigLocation;

    @PostConstruct
    public void init(){
        JacksonUtils.setTimeZone(jacksonDeserializationTimeZone);
    }


    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getVersion()
    {
        return version;
    }

    public void setVersion(String version)
    {
        this.version = version;
    }

    public String getCopyrightYear()
    {
        return copyrightYear;
    }

    public void setCopyrightYear(String copyrightYear)
    {
        this.copyrightYear = copyrightYear;
    }

    public boolean isDemoEnabled()
    {
        return demoEnabled;
    }

    public void setDemoEnabled(boolean demoEnabled)
    {
        this.demoEnabled = demoEnabled;
    }

    public static String getProfile()
    {
        return profile;
    }

    public void setProfile(String profile)
    {
        SuperSaiyanConfig.profile = profile;
    }

    public static String getExcelToHtmlCharsetName() {
        return excelToHtmlCharsetName;
    }

    public void setExcelToHtmlCharsetName(String excelToHtmlCharsetName) {
        SuperSaiyanConfig.excelToHtmlCharsetName = excelToHtmlCharsetName;
    }

    public static boolean isAddressEnabled()
    {
        return addressEnabled;
    }

    public void setAddressEnabled(boolean addressEnabled)
    {
        SuperSaiyanConfig.addressEnabled = addressEnabled;
    }
    public static String getCaptchaType() {
        return captchaType;
    }

    public void setCaptchaType(String captchaType) {
        SuperSaiyanConfig.captchaType = captchaType;
    }
    /**
     * 获取导入上传路径
     */
    public static String getImportPath()
    {
        return getProfile() + "/import";
    }

    /**
     * 获取头像上传路径
     */
    public static String getAvatarPath() {
        return getProfile() + "/avatar";
    }

    public static String getDownloadPath(){
        return getProfile() + "/download/";
    }

    /**
     * 获取上传路径
     */
    public static String getUploadPath()
    {
        return getProfile() + "/upload";
    }

    public String getFontName(){
        return fontName;
    }

    public void setFontName(String fontName) {
        this.fontName = fontName;
        ExcelUtil.fontName=fontName;
    }

    public String getGenCodeZipName() {
        return genCodeZipName;
    }

    public void setGenCodeZipName(String genCodeZipName) {
        this.genCodeZipName = genCodeZipName;
    }

    public String getJacksonDeserializationTimeZone() {
        return jacksonDeserializationTimeZone;
    }

    public void setJacksonDeserializationTimeZone(String jacksonDeserializationTimeZone) {
        this.jacksonDeserializationTimeZone = jacksonDeserializationTimeZone;
    }


    public void setClearDataEnabled(boolean clearDataEnabled) {
        SuperSaiyanConfig.clearDataEnabled = clearDataEnabled;
    }

    public static boolean isClearDataEnabled() {
        return clearDataEnabled;
    }

    public void setRedisRootKeyPrefix(String redisRootKeyPrefix) {
        SuperSaiyanConfig.redisRootKeyPrefix = redisRootKeyPrefix;
    }

    public static String getRedisRootKeyPrefix() {
        return redisRootKeyPrefix;
    }

    public static String getMultipartConfigLocation() {
        return multipartConfigLocation;
    }

    public void setMultipartConfigLocation(String multipartConfigLocation) {
        SuperSaiyanConfig.multipartConfigLocation = multipartConfigLocation;
    }
}
